package com.zyk.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangsan
 * @date 2021/6/19 11:12
 */
public class C1239 {


    // 暴力解
    public static int maxLength(List<String> arr) {
        return dfs(arr, 0, "");
    }

    public static int dfs(List<String> strs, int i, String str) {
        if (i == strs.size()) return 0;
        int p1 = dfs(strs, i+1, str);
        str = str + strs.get(i);
        int p2 = 0;
        if (check(str)) {
            p2 = strs.get(i).length() + dfs(strs, i + 1, str);
        }
        return Math.max(p1, p2);
    }

    public static boolean check(String str) {
        char[] s = str.toCharArray();
        boolean[] help = new boolean[26];
        for (char c : s) {
            if (help[c - 'a']) return false;
            help[c - 'a'] = true;
        }
        return true;
    }

    public static void main(String[] args) {
        List<String> arr = new ArrayList<>();
        arr.add("un");
        arr.add("iq");
        arr.add("ue");
        System.out.println(maxLength(arr));
    }

}
